#! /bin/bash
set -e

NOW_DIR=$(cd -P $(dirname "$0");pwd)

chmod -R 777 ${NOW_DIR}/log
chmod -R 777 ${NOW_DIR}/data
chmod -R 777 ${NOW_DIR}/conf

i=1
num=6
ipStr=''

while (( ${i} <= ${num} ))
do
  #--cluster-enabled yes：开启redis集群
  #--appendonly yes：开启持久化
  #--port 6386：redis端口号
  name=iredis6.2.6-${i}
  port=$[6379+${i}-1]
  dataName=node${i}
  docker run -it -d \
    --name ${name} \
    --net host \
    -v ${PWD}/conf:/usr/local/etc/redis \
    -v ${PWD}/log/${dataName}:/var/log \
    -v ${PWD}/data/${dataName}:/data \
    --restart=always --privileged=true iredis:6.2.6 \
    --cluster-enabled yes --appendonly yes --port ${port}
  let i++
  ipStr="${ipStr} 127.0.0.1:${port}"
done

echo "redis-cli --cluster create ${ipStr} --cluster-replicas 1"





